package com.photographysharing.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.photographysharing.common.ThreadLocalOperation;
import com.photographysharing.dto.CommentDTO;
import com.photographysharing.entity.Comments;
import com.photographysharing.request.SelectByPaging;
import com.photographysharing.response.DatasResponse;
import com.photographysharing.response.MessageResponse;
import com.photographysharing.service.CommentsService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    private CommentsService service;

    public CommentController(CommentsService service) {
        this.service = service;
    }

    @PostMapping("comment")
    public MessageResponse comment(@RequestBody Comments comment){
        String userId = ThreadLocalOperation.getThreadLocalUserId();
        comment.setUserId(userId);
        if(service.comment(comment)){
            return new MessageResponse("评论成功!");
        }
        return new MessageResponse("评论失败!");
    }
    @GetMapping("/comments")
    public DatasResponse<CommentDTO> comments(String photoId){
        return service.getComments(photoId);
    }

    @GetMapping("/selectByPag")
    public DatasResponse<CommentDTO> selectByPag(SelectByPaging pag){
        return service.selectByPag(pag);
    }
}
